<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>管理员列表</title>
</head>

<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 直播管理 <span class="c-gray en">&gt;</span> 直播列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
       title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <input type="text" class="input-text" style="width:250px" placeholder="输入用户昵称/直播描述" id="search_live" name="search_live" value="<%=data.keyword%>">
        <button type="submit" class="btn btn-success" id="" name="" onclick="search_live()"><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
			<a href="javascript:;" onclick="live_add('添加直播','/live/live-add')" class="btn btn-primary radius">
				 <i class="Hui-iconfont">&#xe600;</i> 添加直播
            </a>
            </span> <span class="r">共有数据：<strong><%=(data.length>0?data[0].total:0)%></strong> 条</span> 
    </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr>
            <th scope="col" colspan="11">直播列表</th>
        </tr>
        <tr class="text-c">
            <th width="25"><input type="checkbox" name="" value=""></th>
            <th width="30">头像</th>
            <th width="70">用户昵称</th>
            <th width="210">直播地址</th>
            <th width="30">观看数</th>
            <th width="100">直播描述</th>
            <th width="85">创建时间</th>
            <th width="50">直播封面</th>
            <th width="40">直播状态</th>
            <th width="20">排序</th>
            <th width="60">操作</th>
        </tr>
        </thead>
        <tbody>
        <% for(var i=0;i<data.length;i++){%>
        <tr class="text-c">
            <td>
                <input type="checkbox" value=<%=data[i].liveid%> name="" data-val=
                <%=data[i].liveid%>
            </td>
            <td>
                <img width="32" src=<%=data[i].headerimg%>>
            </td>
            <td>
                <%=data[i].nickname%>
            </td>
            <td>
                <%=data[i].url%>
            </td>
            <td>
                <%=data[i].watchCount%>
            </td>

            <td>
                <%=data[i].description%>
            </td>
            <td>
                <%=new Date(data[i].createdat).toLocaleString()%>
            </td>
            <td>
                <img width="40" src=<%=data[i].thumb%>>
            </td>
            <td>
                <span class="label <%=data[i].status==1?'label-success':''%> radius"><%=data[i].status==1?'开启':'关闭'%></span>
            </td>
            <td>
                <%=data[i].order%>
            </td>
            <td class="td-manage">
                <a title="禁用" href="javascript:;" onClick="admin_stop(this,'<%=data[i].liveid%>','0')" style="text-decoration:none" >
                    <i class="Hui-iconfont">&#xe631;</i>
                </a>
                <a title="启用" href="javascript:;" onclick="admin_start(this,'<%=data[i].liveid%>','1')" class="ml-5" style="text-decoration:none">
                    <i class="Hui-iconfont">&#xe615;</i>
                </a>
                <a title="删除" href="javascript:;" onclick="admin_del(this,'<%=data[i].liveid%>')" class="ml-5" style="text-decoration:none">
                    <i class="Hui-iconfont">&#xe6e2;</i>
                </a>
                <a title="编辑" href="javascript:;" onclick="admin_edit('编辑', '/live/live-edit?liveid=<%=data[i].liveid%>','900','700')" class="ml-5" style="text-decoration:none">
                    <i class="Hui-iconfont">&#xe6df;</i>
                </a>
                <a title="置顶" href="javascript:;" onclick="admin_gotop(this,'<%=data[i].liveid%>','0', '<%=data[i].order%>')" class="ml-5" style="text-decoration:none">
                    <i class="Hui-iconfont">&#xe684;</i>
                </a>
            </td>
        </tr>
        <%}%>
        </tbody>
    </table>
    <div id="page1"></div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    function demo(curr) {
        var obj = location.href.match(/page=(\d+)/);
        var page = 1;
        if (obj !== null) {
            page = obj[1];
            console.log('当前页：' + page);
            //显示分页
            laypage({
                cont: 'page1', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                pages:Math.ceil(<%=((data.length>0?data[0].total:0) / 10)%>), //通过后台拿到的总页数
                    //curr: curr || 1, //当前页
                    curr: function () { //通过url获取当前页，也可以同上（pages）方式获取

                return page ? page : 1;
            }(),
                    jump: function (e, first) { //触发分页后的回调
                if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                    //demo(e.curr);
                    var keyword = $('#search_user').val();
                    location.href = "/live/live-list?page=" + e.curr + '&keyword=' + keyword;
                }
            }
        });
        }
    }

    demo(1);

    function live_add(title, url) {
        //layer_show(title, url, w, h);
        location.href='/live/live-add';
    }

    /*管理员-停用*/
    function admin_stop(obj, id, status) {
        layer.confirm('确认要禁用吗？', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: 'POST',
                url: '/live/modify-live-status',
                dataType: 'json',
                data: {
                    objectid: id,
                    status: status
                },
                success: function (data) {
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
                    layer.msg('已禁用!', { icon: 1, time: 2000 });
                    location.replace(location.href)
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
            
        });
    }

    /*管理员-启用*/
    function admin_start(obj, id, status) {
        layer.confirm('确认要启用吗？', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: 'POST',
                url: '/live/modify-live-status',
                dataType: 'json',
                data: {
                    objectid: id,
                    status: status
                },
                success: function (data) {
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                    layer.msg('已启用!', { icon: 1, time: 2000 });
                    location.replace(location.href)
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }

    /*管理员-删除*/
    function admin_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: 'POST',
                url: '/live/delete-live',
                dataType: 'json',
                data: {
                    objectid: id
                },
                success: function (data) {
                    layer.msg('已删除!', { icon: 1, time: 2000 });
                    location.replace(location.href)
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }

    function admin_gotop(obj, id, order, oldOrder) {
        layer.confirm('是否置顶', function (index) {
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: 'POST',
                url: '/live/live-gotop',
                dataType: 'json',
                data: {
                    objectid: id,
                    order: order,
                    oldOrder: oldOrder
                },
                success: function (data) {
                    location.replace(location.href)
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }

    function admin_edit(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    function search_live() {
        var keyword = $('#search_live').val();
        location.href = '/live/live-list?page=1&keyword=' + keyword
    }

</script>
</body>

</html>